<?php $var_path = $_SERVER['DOCUMENT_ROOT'];

      $var_path .= "/AppSaleOnline/asset/css/style.css";
?>
<!-- xử lý mã lệnh php lấy thông tin người dùng bind vào form -->
<?php
// echo $_SERVER['DOCUMENT_ROOT'];
require_once("../../model/user.php"); // admin/view/
// echo getcwd(); // Xem thư mục hiện của bạn là gì???

// echo getcwd();
// echo dirname("../../model/user.php"); // xem thư mục của file nằm ở đâu

// lay du lieu bien tren trinh duyet
if(isset($_GET['user_id']))
{
    $user_id = $_GET['user_id'];
    $user_account_information = new User();
    $data = $user_account_information->get_account_information($user_id); // lay thong tin user voi user_id
}else{

    header("location:admin.php");
}

// do thong tin ra vao cac form
?>
<!DOCTYPE html>
<head>
    <meta charset="utf-8"/>
    <style type="text/css">
        #loading{
            margin-top: 20px;
            width: 500px;
            margin: 0px auto;
            text-align: center;
            padding: 30px;
            -moz-border-radius: 8px;
            -webkit-border-radius: 8px;
            border-radius: 8px;
            border: 1px solid #fff;
            box-shadow: 1px 2px 3px 0;
        }
        #clear-fix{
            clear: both;
        }
        .change-info{
            margin-top: 2px;
        }
    </style>
    <link rel="stylesheet" type="text/css" href="../../assets/css/style.css"/>
    <script src="../../assets/jquery-1.10.2.js" type="text/javascript"></script>
    <script type="text/javascript">

        $("document").ready(function(e){
            $("#loading").hide();
            $("#btnSua").click(function(e){
                var request = $.ajax({
                    type: "post",
                    data: {
                        // userid
                        "user_id" : <?php echo $_GET['user_id'];?>, // ky thuat chen code php trong javascript
                        // username
                        "username" : $("#formEditInformation :text[name='txtUserName']").val(),
                        // address
                        "address" : $("#formEditInformation :text[name='txtAddress']").val(),
                        // telephone
                        "telephone" : $("#formEditInformation :text[name='txtTelephone']").val(),
                        // sex
                        "gioitinh" : $("#formEditInformation :radio[name='txtGT']").val(),
                        // email
                        "email": $("#formEditInformation :text[name='txtEmail']").val()
                    },
                    dataType: "json",
                    url: "../../controller/sua_thong_tin_user.php"
                });
                request.done(function(response,status){
                    console.log(response); // hien thong tin cua response tra ve
                    console.log(status);
                    $("#loading").show().html("Loading...");
                    // alert(response);
                    
                    var msg = response.thongbao;
                    setTimeout(function(){   
                        var html = "";
                        $.each(msg, function(i, val)
                        {
                            html += val;
                        });
                        $("#loading").show().html(html);
                    }, 1000); // hien thanh cong trong vong 2 giay
                });
            });

        });

    </script>
</head>

<body>


<div id="wrapper">


    <div id="form-thong-tin" >


        <form method="post" action="" id="formEditInformation" class="form-horizontal">

            <fieldset>


                <legend>Thông tin tài khoản người dùng</legend>

                <!-- username text -->
                <div class="form-group">
                    <label for="username" class="col-sm-2 control-label">Username:</label>
                    <div class="col-xs-3">
                        <input type="text" value="<?php echo $data[0]["username"];?>" name="txtUserName" class="form-control input-sm"/>
                    </div>
                </div>




                <!-- user address -->
                <div class="form-group">    
                    <label for="address" class="col-sm-2 control-label">Address:</label>
                    <div class="col-xs-3">
                        <input type="text" value="<?php echo $data[0]["user_address"];?>" name="txtAddress" class="form-control input-sm"/>
                    </div>
                </div>

                <!-- Gioi tinh -->

                <div class="form-group">
                    <label for="sex" class="col-sm-2 control-label">Giới tính:</label>

                    <div class="col-xs-3">
                        <!-- male -->
                        <input type="radio" value="1" name="txtGT"/>Male
                        <!-- female radio -->
                        <input type="radio" value="0" name="txtGT"/>Female
                    </div>
                </div>
                <!-- So điện thoại -->
                
                <div class="form-group">
                    <label class="col-sm-2 control-label">Telephone:</label>
                    <div class="col-xs-3">
                        <input type="text" value="<?php echo $data[0]["user_telephone"];?>" name="txtTelephone" class="form-control input-sm"/>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 control-label">Email:</label>
                    <div class="col-xs-3">
                        <input type="text" value="<?php echo $data[0]["user_email"];?>" name="txtEmail" class="form-control input-sm"/>
                    </div>
                </div>
                    
                <!-- submit thay đổi thông tin -->
                <div class="change-info">
                
                    <label class="col-sm-2 control-label"></label>
                    <div class="col-xs-3">
                        <input type="button" name="btnSua" value="Sửa" id="btnSua" class="btn-info btn btn-sm"/>
                    </div>
                </div>
                


            </fieldset>


        </form>
    </div>


    <!-- clear-fix -->
    <div id="clear-fix">

    </div>
    <!-- load du lieu khi edit thong tin tai khoan -->
    <div id="loading">




    </div>


</div>

</body>





